﻿using System;
using System.Configuration;
using System.ServiceModel;

namespace MvePublicService
{
	/*
	 * 日本SGI株式会社
	 * ヨハンソン・ヘンリク
	 * johansson@sgi.co.jp
	 * 
	 * Change Log:
	 * ---------------------------------------------------------------------------
	 * 2009.01.07	Johansson Henrik		Class Created.
	 * 
	 */

	/// <summary>
	/// Program entry point.
	/// This is a Console (Self) Hosted Service, 
	/// so this is the actual entry point of the Service Executable.
	/// </summary>
	/// <remarks>INSERT:Creds</remarks>
	class ServiceConsoleHost
	{
		[STAThread]
		static void Main(string[] args)
		{
			Console.WriteLine("Bringing Service Online...");
			try
			{
				Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
				UserManager.ValidLoginPeriodInHours = int.Parse(ConfigurationManager.AppSettings["ValidLoginPeriodInHours"]);

				using (ServiceHost serviceHost = new ServiceHost(typeof(PublicService), baseAddress))
				{
					serviceHost.Open();

					Console.WriteLine("The Service is ready.");
					Console.WriteLine("Service Name = {0}.", ConfigurationManager.AppSettings["serverName"]);
					Console.WriteLine("Service Address = {0}", ConfigurationManager.AppSettings["baseAddress"]);
					Console.WriteLine("Press <ENTER> to terminate the Service.");
					Console.WriteLine();
					Console.ReadLine();
					serviceHost.Close();

				}
			}
			catch (CommunicationException ex)
			{
				Console.WriteLine("An exception occured: {0}", ex.Message);
				Console.WriteLine("Press Enter to close eJournalServer.");
				Console.ReadLine();

				return;
			}
		}//end:Main
	}
}
